package com.cssy.xxkj.attach.util;

import java.util.ArrayList;
import java.util.List;

public class ArrayUtils extends org.apache.commons.lang.ArrayUtils{

	@SuppressWarnings("rawtypes")
	public static List splitToFixedList(List ids,int num){
		return splitToFixedList(ids,num,true);
	}
	
	
	
	@SuppressWarnings("rawtypes")
	public static List splitToFixedList(List ids,int num,boolean fixedLastList){
		List<List<Object>> result = new ArrayList<List<Object>>();
		List<Object> l = new ArrayList<Object>();
		for(int i=0;i<ids.size();i++){
			if(i==0 || i % num != 0){
				l.add(ids.get(i));
			}else{
				result.add(l);
				l = new ArrayList<Object>();
				l.add(ids.get(i));
			}
		}
		if(l.size()>0&&fixedLastList){
			fixed(l,num);
		}
		if (!l.isEmpty()&&!result.contains(l))
			result.add(l);
		return result;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static List fixed(List ids, int num) {
		Object id = ids.get(0);
		int s = ids.size();
		for (int i = s; i < num; i++) {
			ids.add(id);
		}
		return ids;
	}
}
